package start.spring.basic.report.controller.filltemplete;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.security.annotation.RequiresPermissions;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import start.spring.basic.log.ServiceLog;
import start.spring.basic.page.PageQuery;
import start.spring.basic.page.PageResult;
import start.spring.basic.report.common.SysConstant;
import start.spring.basic.report.controller.BaseController;
import start.spring.basic.report.entity.ReportTempleteDesign;
import start.spring.basic.report.service.filltemplete.IReportTempleteDesignService;
import start.spring.basic.response.ResponseData;
import start.spring.basic.response.ResponsePage;

/**
 * 
 * @author xyy
 * @date 2023-12-27
 *
 */
@RestController
@RequestMapping("/templetedesign")
@Api(tags = "模板设计相关接口")
public class ReportTempleteDesignController extends BaseController {
	
    @Autowired
    private IReportTempleteDesignService reportTempleteDesignService;
	
    @ServiceLog(businessType = "查询模板设计列表", systemType = SysConstant.SYSTEM_TYPE, recordResult = false, userId = "")
    @RequiresPermissions("report:templetedesign:list")
    @PostMapping("/list")
    @ApiOperation(value = "查询模板设计列表", notes = "分页查询")
    public ResponsePage<ReportTempleteDesign> list(PageQuery pageQuery, @RequestBody ReportTempleteDesign reportTempleteDesign) {
    	return super.returnResponse(this.reportTempleteDesignService.selectReportTempleteDesignPageList(pageQuery, reportTempleteDesign));
    }
    
    @ServiceLog(businessType = "查询模板设计详情", systemType = SysConstant.SYSTEM_TYPE, recordResult = true, userId = "")
    @RequiresPermissions("report:templetedesign:list")
    @PostMapping("/detail")
    @ApiOperation(value = "查询模板设计详情", notes = "单条记录详情查询")
    public ResponseData<ReportTempleteDesign> detail(@RequestBody ReportTempleteDesign reportTempleteDesign) {
    	PageResult<ReportTempleteDesign> pageResult = this.reportTempleteDesignService.selectReportTempleteDesignPageList(new PageQuery(), reportTempleteDesign);
    	if(pageResult.getRecords()!=null&&!pageResult.getRecords().isEmpty()) {
    		ReportTempleteDesign detail = pageResult.getRecords().get(0);
    		return ResponseData.successData(detail);
    	}else {
    		return ResponseData.errorMsg("未查询到详细信息！");
    	}
    }
    
    @ServiceLog(businessType = "查询可填报模板列表", systemType = SysConstant.SYSTEM_TYPE, recordResult = false, userId = "")
    @GetMapping("/list/canfill")
    @ApiOperation(value = "查询可填报模板列表", notes = "全量查询")
    public ResponseData<List<ReportTempleteDesign>> listCanfill() {
    	return this.reportTempleteDesignService.selectCanfillTempleteList();
    }
	
    @ServiceLog(businessType = "新增模板设计", systemType = SysConstant.SYSTEM_TYPE, recordResult = true, userId = "")
    @RequiresPermissions("report:templetedesign:add")
    @PostMapping("/add")
    @ApiOperation(value = "新增模板设计", notes = "")
    public ResponseData<String> add(@RequestBody ReportTempleteDesign reportTempleteDesign) {
        return this.reportTempleteDesignService.insertReportTempleteDesign(reportTempleteDesign);
    }
	
    @ServiceLog(businessType = "修改模板设计", systemType = SysConstant.SYSTEM_TYPE, recordResult = true, userId = "")
    @RequiresPermissions("report:templetedesign:edit")
    @PostMapping("/edit")
    @ApiOperation(value = "修改模板设计", notes = "")
    public ResponseData<String> edit(@RequestBody ReportTempleteDesign reportTempleteDesign) {
    	return this.reportTempleteDesignService.updateReportTempleteDesign(reportTempleteDesign);
    }
	
    @ServiceLog(businessType = "删除模板设计", systemType = SysConstant.SYSTEM_TYPE, recordResult = true, userId = "")
    @RequiresPermissions("report:templetedesign:remove")
    @PostMapping("/remove")
    @ApiOperation(value = "删除模板设计", notes = "")
    public ResponseData<String> remove(@RequestBody List<Long> templeteIds) {
    	return this.reportTempleteDesignService.deleteReportTempleteDesignByTempleteIds(templeteIds);
    }
    
}
